package cn.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 简单数据绑定
 */
@RestController
@RequestMapping("simple")
public class SimpleController {

    @RequestMapping("getUser")
    public String getUser(Integer id) {
        return "success, id = " + id;
    }
    /**
     * 访问 http://localhost:8080/simple/getUser?id=2
     * 页面 "success, id = 2"
     */

    // 使用@RequestParam注解进行间接数据绑定
    @RequestMapping("findUser")
    public String findUser(@RequestParam("uid") Integer id) {
        return "success, id = " + id;
    }
    /**
     * 访问 http://localhost:8080/simple/findUser?id=3
     * 报404错误
     *
     * http://localhost:8080/simple/findUser?uid=3
     * 页面 "success, id = 3"
     */
}
